package cn.bigway.app.weavingdesigner.operator;

import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;

import javax.swing.event.MouseInputListener;

import cn.bigway.app.weavingdesigner.log.WdLog;
import cn.bigway.app.weavingdesigner.weaving.WdDocPanel;

public abstract class WdDocOperator implements KeyListener, MouseInputListener,
		MouseWheelListener {

	protected WdDocPanel getDocPanel(KeyEvent event) {
		return (WdDocPanel) event.getComponent();
	}

	protected WdDocPanel getDocPanel(MouseEvent event) {
		return (WdDocPanel) event.getComponent();
	}

	protected WdDocPanel getDocPanel(MouseWheelEvent event) {
		return (WdDocPanel) event.getComponent();
	}

	@Override
	public void mouseClicked(MouseEvent event) {
		WdLog.debug("event=" + event.toString());
	}

	@Override
	public void mouseEntered(MouseEvent event) {
		WdLog.debug("event=" + event.toString());
	}

	@Override
	public void mouseExited(MouseEvent event) {
		WdLog.debug("event=" + event.toString());
	}

	@Override
	public void mousePressed(MouseEvent event) {
		WdLog.debug("event=" + event.toString());
		if (event.getModifiers() == InputEvent.BUTTON2_MASK) {
			getDocPanel(event).setZoom(1.0);
		}
	}

	@Override
	public void mouseReleased(MouseEvent event) {
		WdLog.debug("event=" + event.toString());
	}

	@Override
	public void mouseDragged(MouseEvent event) {
		WdLog.debug("event=" + event.toString());
	}

	@Override
	public void mouseMoved(MouseEvent event) {
		WdLog.debug("event=" + event.toString());
	}

	@Override
	public void mouseWheelMoved(MouseWheelEvent event) {
		WdLog.debug("event=" + event.toString());
		getDocPanel(event).setZoom(
				getDocPanel(event).getZoom() + event.getWheelRotation()
						* (event.isControlDown() ? 10.0 : 1.0) / 10);
	}

	@Override
	public void keyPressed(KeyEvent event) {
		WdLog.debug("event=" + event.toString());
	}

	@Override
	public void keyReleased(KeyEvent event) {
		WdLog.debug("event=" + event.toString());
	}

	@Override
	public void keyTyped(KeyEvent event) {
		WdLog.debug("event=" + event.toString());
	}
}
